package org.recruit.system.controller;

import org.recruit.system.domain.Offer;
import org.recruit.system.service.IOfferService;
import org.recruit.system.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 企业面试邀请Controller
 * 
 * @author teapot
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/system/offer")
public class OfferController
{
    private String prefix = "system/offer";

    @Autowired
    private IOfferService offerService;

    @GetMapping()
    public String offer()
    {
        return prefix + "/offer";
    }

    /**
     * 查询企业面试邀请列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(Offer offer)
    {
        //startPage();
        List<Offer> list = offerService.selectOfferList(offer);
        return AjaxResult.success(list);
    }


    /**
     * 新增企业面试邀请
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业面试邀请
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Offer offer)
    {
        return AjaxResult.success(offerService.insertOffer(offer));
    }

    /**
     * 修改企业面试邀请
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Offer offer = offerService.selectOfferById(id);
        mmap.put("offer", offer);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业面试邀请
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Offer offer)
    {
        return AjaxResult.success(offerService.updateOffer(offer));
    }

    /**
     * 删除企业面试邀请
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return AjaxResult.success(offerService.deleteOfferByIds(ids));
    }
}
